/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import business.Comment;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;

/**
 *
 * @author Admin
 */
public class CommentIO 
{
    public static void append(Comment comment, String filePath) 
            throws IOException
    {
        File file = new File(filePath);
        FileWriter fw = new FileWriter(file, true);
        PrintWriter out = new PrintWriter(fw);
        out.println(comment.getName() + "|" + comment.getComment());
        out.close();
    }
    
    public static String read(String filePath)
            throws IOException
    {
        File file = new File(filePath);
        FileReader fr = new FileReader(file);
        BufferedReader in = new BufferedReader(fr);
        StringBuilder sb = new StringBuilder();
        
        String temp;
        // andiamo a leggere riga per riga
        while((temp = in.readLine()) != null)
        {
            //sb.append(temp + "\n");
            sb.append(temp + "<br />");
        }
        
        return sb.toString();
    }
}
